package event.money.tracker;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.SimpleAdapter;
import android.widget.TextView;

public class MultipleChoiceAdapter extends SimpleAdapter
{  
	public final static String NAME = "DrawingName";    
    public final static String PHONE_NUMBER = "DrawingPhone";  
  Map<Integer, Boolean> map;   
    
  LayoutInflater mInflater;  
    
  private List<? extends Map<String, ?>> mList;  
    
  public MultipleChoiceAdapter(Context context, List<Map<String, String>> data,  
          int resource, String[] from, int[] to) {  
      super(context, data, resource, from, to);  
      map = new HashMap<Integer, Boolean>();  
      mInflater = LayoutInflater.from(context);  
      mList = data;  
      for(int i = 0; i < data.size(); i++) {  
          map.put(i, false);  
      }   
  }  
  
  public boolean IsChecked( int aPosition )
  {
	  return map.get( Integer.valueOf( aPosition ) );
  }
  
  public String GetName( int aPosition )
  {
	return (String)mList.get(aPosition).get(NAME);  
  }
  
  public String GetPhoneNum( int aPosition )
  {
	  return (String)mList.get(aPosition).get(PHONE_NUMBER);
  }
    
  @Override  
  public int getCount() {  
      return mList.size();  
  }  

  @Override  
  public Object getItem(int position) {  
      return position;  
  }  

  @Override  
  public long getItemId(int position) {  
      return position;  
  }  
    
  @Override  
  public View getView(int position, View convertView, ViewGroup parent) {  
      if(convertView == null) {  
          convertView = mInflater.inflate(R.layout.contact_items, null);  
      }  
      TextView tN = (TextView) convertView.findViewById(R.id.ContactNameTV);  
      tN.setText((String)mList.get(position).get(NAME));  
        
      TextView tP = (TextView) convertView.findViewById(R.id.ContactPhoneTV);  
      tP.setText((String)mList.get(position).get(PHONE_NUMBER));  
        
      CheckBox checkBox = (CheckBox) convertView.findViewById(R.id.ContactCheckBox);  
        
      checkBox.setChecked(map.get(position));   
        
      return convertView;  
  }
    
}  